package com.xiecong.mapper;

import com.xiecong.pojo.Emp;
import com.xiecong.pojo.EmpQueryParam;
import com.xiecong.pojo.JobData;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    List<Emp> pageQuery(EmpQueryParam empQueryParam);


    /**
     * 添加员工
     * @param emp
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    /**
     * 批量删除
     * @param ids
     */
    void deleteByIds(List<Integer> ids);


    /**
     * 根据id查询
     * @param id
     * @return
     */
    /*@Select("select e.*, d.name deptName from emp e left join dept d on e.dept_id = d.id where e.id in (#{id})")
    Emp findById(Integer id);*/

    /**
     * 根据id查询员工-映射
     * @param id
     * @return
     */
    Emp findById(Integer id);


    /**
     * 更新员工
     * @param emp
     * @return
     */
    void updateById(Emp emp);


    /**
     * 员工职位统计
     * @return
     */
    List<JobData> empJobData();


    /**
     * 员工性别人数统计
     * @return
     */
    @MapKey("name")//可以没有，要写的话，要用唯一的字段值，name
    List<Map<String, Object>> genderData();


    /**
     * 查询所有员工信息-添加班级中班主任显示
     */
    List<Emp> findAll();


    /**
     * 查询所有部门id
     * @return
     */
    List<Integer> findAllDeptpId();


    /**
     * 登录-根据用户名和密码查询员工表
     */
    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp findByUsernameAndPassword(String username, String password);

    @Select("select image from emp")
    List<String> selectAllImages();


    /*@Select("select count(*) from emp e left join dept d on e.dept_id = d.id ")
    Long count();

    @Select("select d.name deptName, e.* from emp e left join dept d on e.dept_id = d.id limit #{start},#{pageSize}")
    List<Emp> findByPage(@Param(value = "start") Integer start,@Param(value = "pageSize") Integer pageSize);*/
}
